

(function(Global /*, context */) {

function OnDOTAShowAbilityTooltip(panel,abilityName,itemSlot) {

    // $.Msg(panel)
    var tooltips = Global.Panel.dotaHud.FindChildTraverse("Tooltips")
    if(tooltips !== null)
    {


        var abilityNameTp= tooltips.FindChildTraverse("AbilityName");
        var abilityLevelTp= tooltips.FindChildTraverse("AbilityLevel");

            var abilityId=panel.abilityid;

            if(abilityId===undefined){
                abilityId=Entities.GetAbilityByName(Players.GetPlayerHeroEntityIndex( Players.GetLocalPlayer()),abilityName)
            }

            var abilityUpgradeLevelTp= tooltips.FindChildTraverse("AbilityUpgradeLevel")

            if(abilityNameTp===null||abilityLevelTp==null){
                return
            }

            if(Abilities.GetAbilityType(abilityId)===ABILITY_TYPES.ABILITY_TYPE_ULTIMATE){
                abilityNameTp.style.color=Global.Config.abilityUltColor;
                abilityLevelTp.style.color=Global.Config.abilityUltColor;
            }
            else if((Abilities.GetBehavior(abilityId) & DOTA_ABILITY_BEHAVIOR.DOTA_ABILITY_BEHAVIOR_PASSIVE)!== 0){
                abilityNameTp.style.color=Global.Config.abilityAttrColor;
                abilityLevelTp.style.color=Global.Config.abilityAttrColor;
            }
            else if(Abilities.GetAbilityType(abilityId)===-1){
                abilityNameTp.style.color=null;
                abilityLevelTp.style.color=null;
            }
            else {
                abilityNameTp.style.color=Global.Config.abilityBasicColor;
                abilityLevelTp.style.color=Global.Config.abilityBasicColor;
            }

           if(Abilities.GetLevel(abilityId)===Abilities.GetMaxLevel( abilityId)){
               abilityLevelTp.text="MAX"
           }
           else {
               abilityLevelTp.text=$.Localize("#DOTA_ToolTip_Level")+ Abilities.GetLevel(abilityId)
           }
            abilityUpgradeLevelTp.text="";

    }
}



    function OnDOTAShowEconItemTooltip(itemDef,entID,itemSlot) {
        // $.Msg(itemDef,abilityId)
        var tooltips = Global.Panel.dotaHud.FindChildTraverse("Tooltips")
        if (tooltips !== null) {
            var abilityNameTp = tooltips.FindChildTraverse("AbilityName");
            var abilityLevelTp = tooltips.FindChildTraverse("AbilityLevel");
            abilityNameTp.style.color = null
            abilityLevelTp.style.color = null
        }
    }

    $.RegisterForUnhandledEvent('DOTAShowAbilityInventoryItemTooltip', OnDOTAShowEconItemTooltip)
    $.RegisterForUnhandledEvent('DOTAShowAbilityTooltipForEntityIndex', OnDOTAShowAbilityTooltip)
    $.RegisterForUnhandledEvent('DOTAShowAbilityTooltip', OnDOTAShowAbilityTooltip)

})(GameUI.CustomUIConfig(), this);